require 'rubygems'
require 'mongrel'

class LoadTestHandler < Mongrel::HttpHandler
  include Mongrel::HttpHandlerPlugin
  def process(request, response)
    response.start(200,true) do |head,out|
      sleep 0.001 # use a small delay to simulate network latency...
      out << %Q(<html><body>Test Document</body></html>)
    end
  end
end

def start_net_server(port)
  config = Mongrel::Configurator.new( :host => "127.0.0.1", :port => port ) do
    listener do
      uri "/", :handler => LoadTestHandler.new
    end
    trap("INT") { stop }
  end
  config.run
  config
end
